Load Libraries

library(plotly)    # for 3D plotting

3D Plot

plot_ly(iris, x=~Petal.Width, y=~Sepal.Length, z=~Sepal.Width) %>%
  add_markers() 

Update Labels and Title

plot_ly(iris, x=~Petal.Width, y=~Sepal.Length, z=~Sepal.Width) %>%
  add_markers() %>%
  layout(
    title = "3D Scatter Plot: Iris Data",
    scene = list(xaxis = list(title = "Petal Width"),
                 yaxis = list(title = "Sepal Length"),
                 zaxis = list(title = "Sepal Width"))
  )

Color by Species

plot_ly(iris, x=~Petal.Width, y=~Sepal.Length, z=~Sepal.Width,
        color = ~Species) %>%
  add_markers() %>%
  layout(
    title = "3D Scatter Plot by Species: Iris Data",
    scene = list(xaxis = list(title = "Petal Width"),
                 yaxis = list(title = "Sepal Length"),
                 zaxis = list(title = "Sepal Width"))
  )